package com.huangwenshuo.futurestarschoolmanagement.controller;

import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.ActivityDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.ActivitysVo;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.service.ActivityUsersService;
import com.huangwenshuo.futurestarschoolmanagement.service.ActivitysService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivitysService activitysService;
    @Autowired
    private ActivityUsersService activityUsersService;

    @GetMapping("/getActivitys")
    public Result getActivitys(ActivityDto.ActivityPage activityPage){
        Map<String,Object> res = null;
        try {
            res = activitysService.getActivitys(activityPage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), res,"查询成功");
    }

    @GetMapping("/getActivityById")
    public Result getActivityById(ActivityDto.ActivityPage activityPage){
        ActivitysVo activitysVo= null;
        try {
            activitysVo = activitysService.getActivityById(activityPage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), activitysVo,"查询成功");
    }

    @PostMapping("/updateAct")
    public Result updateAct(@RequestBody() ActivityDto.UpdateAct updateAct){
        try {
            activitysService.updateAct(updateAct);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "更新失败," + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"更新成功");
    }

    @PostMapping("/addAct")
    public Result addAct(@RequestBody ActivityDto.AddAct addAct){
        try {
            activitysService.addAct(addAct);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "添加失败," + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"添加成功");
    }
    @GetMapping("/apply")
    public Result apply(Integer uid ,Integer aid){
        try {
            activitysService.apply(uid,aid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"报名成功");
    }
    @GetMapping("/getActApply")
    public Result getActApply(ActivityDto.ActivityPage activityPage){
        Map<String,Object> res = null;
        try {
            res = activitysService.getActApply(activityPage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), res,"查询成功");
    }


}
